home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / dcopy332.zip / DCMAIN.C < prev    next >
C/C++ Source or Header  |  1990-04-14  |  3KB  |  96 lines

  1. /*************************************************************
  2.  *                                                           *
  3.  * Program DCOPY - physical sector to sector copy              *
  4.  * Copyright (c) 1986 Joerg Genius, Munich, West-Germany     *
  5.  *                                                           *
  6.  * Rev. 3.1.2 added /r command to verify only                *
  7.  * Rev. 3.3.0 added support for 3.5" disks                   *
  8.  *************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <sys\types.h>
  13. #include <sys\stat.h>
  14. #include "dcdefs.h"
  15.  
  16.  
  17. main(argc,argv)
  18.  
  19. int argc;
  20. char *argv[];
  21.  
  22. {
  23.    int source,destination;
  24.    FILE *fopen(),*outfile;
  25.    char filename[257];
  26.  
  27.    printf (text[0],VERSION);
  28.    printf (text[1],REV_DATE);
  29.    if (dcinit()==-1) {
  30.       fprintf (stderr,text[2]);
  31.       return (-1);
  32.    }
  33.    if (argc<3 || argc>5) {
  34.       usage();
  35.       return (0);
  36.    }
  37.    if (argv[1][1]!=':' && argv[2][1]!=':') {
  38.       usage();
  39.       return (0);
  40.    }
  41.    if (argv[2][1]==':' && argv[1][1]==':' && argv[2][2]=='\0' && argv[1][2]=='\0') {
  42.       source=toupper(argv[1][0])-'A';
  43.       destination=toupper(argv[2][0])-'A';
  44.       if (source==destination) {
  45.          fprintf (stderr,text[3]);
  46.          return (0);
  47.       }
  48.       if (source<0 || source>MAX_DRV || destination<0 || destination>MAX_DRV) {
  49.          fprintf (stderr,text[4],MAX_DRV+'A');
  50.          return (0);
  51.       } 
  52.       dcopy(source,destination,(strcmp(argv[3],"/v")==0 ? 1 : 
  53.                                (strcmp(argv[3],"/r")==0 ? 2 : 0)));
  54.    }
  55.    else if (argv[1][1]==':' && argv[1][2]=='\0') {
  56.       source=toupper(argv[1][0])-'A';
  57.       if (source<0 || source>MAX_DRV) {
  58.          fprintf (stderr,text[4],MAX_DRV+'A');
  59.          return (0);
  60.       } 
  61.       strcpy(filename,argv[2]);
  62.       if (strchr(argv[2],'.')==NULL)
  63.            strcat(filename,".IMG");
  64.       if ((outfile=fopen(filename,"wb"))==NULL) {
  65.            fprintf (stderr,text[5],filename);
  66.            return (0);
  67.       }
  68.       if (dfdestination(filename,source,outfile,(strcmp(argv[3],"/n")==0 || strcmp(argv[4],"/n")==0 ? 1 : 0))==0)
  69.          fclose (outfile);
  70.       else {
  71.          fclose (outfile);
  72.          unlink (filename);
  73.       }
  74.    }
  75.    else if (argv[2][1]==':' && argv[2][2]=='\0') {
  76.       destination=toupper(argv[2][0])-'A';
  77.       if (destination<0 || destination>MAX_DRV) {
  78.          fprintf (stderr,text[4],MAX_DRV+'A');
  79.          return (0);
  80.       } 
  81.       strcpy(filename,argv[1]);
  82.       if (strchr(argv[1],'.')==NULL)
  83.            strcat(filename,".IMG");
  84.       if ((outfile=fopen(filename,"rb"))==NULL) {
  85.            fprintf (stderr,text[6],filename);
  86.            return (0);
  87.       }
  88.          dfsource(filename,outfile,destination,(strcmp(argv[3],"/v")==0 || strcmp(argv[4],"/v")==0 ? 1 :
  89.                                                (strcmp(argv[3],"/r")==0 || strcmp(argv[4],"/r")==0 ? 2 : 0)),
  90.                                                (strcmp(argv[3],"/n")==0 || strcmp(argv[4],"/n")==0 ? 1 : 0));
  91.       fclose (outfile);
  92.    }
  93.    else
  94.       usage();
  95. }
  96.